package com.example.administrator.yuejian2.model;


import com.example.administrator.yuejian2.RetrofitListener.RetrofitListener;
import com.example.administrator.yuejian2.bean.MeBean;
import com.example.administrator.yuejian2.service.MyService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.administrator.yuejian2.other.Url.BASEURL;
import static com.example.administrator.yuejian2.other.Url.URL1;

public class MyModel {
    private Retrofit retrofit;
    private MyService myService;

    public MyModel()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL+URL1)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        myService=retrofit.create(MyService.class);
    }
    public void myInfo(String user_id , final RetrofitListener listener)
    {
        Call<MeBean> call=myService.getMe(user_id);
        call.enqueue(new Callback<MeBean>() {
            @Override
            public void onResponse(Call<MeBean> call, Response<MeBean> response) {
                listener.onSuccess(response.body(),1);
            }

            @Override
            public void onFailure(Call<MeBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }
}
